import FCollider, { ColliderType } from "./FCollider";
import { Intersection } from "./Intersection";

const { ccclass, property, menu } = cc._decorator;

@ccclass
@menu("碰撞组件Ex/FPolygonCollider")
export default class FPolygonCollider extends FCollider {
    public worldPoints: cc.Vec2[] = [cc.v2(-100, 0), cc.v2(0, 50), cc.v2(100, 0)];
    public worldEdge: cc.Vec2[] = [];
    public get type() {
        return ColliderType.Polygon;
    }

    @property({ type: [cc.Vec2] })
    private _points: cc.Vec2[] = [cc.v2(-50, -50), cc.v2(50, -50), cc.v2(50, 50), cc.v2(-50, 50)];
    @property({ type: [cc.Vec2] })
    public get points(): cc.Vec2[] {
        return this._points;
    }
    public set points(value: cc.Vec2[]) {
        this._points = value;
    }

    public initCollider(): void {
        super.initCollider();
        this.isConvex = !Intersection.isConcavePolygon(this.points);
    }
}
